package com.banquetmanagementsystem.mapper;


import com.banquetmanagementsystem.pojo.entity.RefreshToken;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 单点登录长时效Token
 * @author 86176
 */
@Mapper
public interface RefreshTokenMapper {
    /**
     * 插入新用户长时效Token
     * @param refreshToken 创建token记录
     * @return 受影响的条数
     */
    @Insert("INSERT INTO  refresh_token(refresh_token, user_id) VALUES(#{refreshToken}, #{userId})")
    Integer insertRefreshToken(RefreshToken refreshToken);

    /**
     * 更新用户长时效Token
     * @param refreshToken 更新token记录
     * @return 受影响的条数
     */
    @Update("UPDATE refresh_token SET refresh_token = #{refreshToken} ,status=TRUE WHERE user_id = #{userId}")
    Integer updateRefreshToken(RefreshToken refreshToken);

    /**
     * 更新当前token状态为失效
     * @param userId 用户id
     * @return 受影响的条数
     */
    @Update("UPDATE refresh_token SET status = FALSE WHERE user_id = #{userId}")
    Integer updateRefreshTokenStatus(Integer userId);

    /**
     * 查询token状态
     * @param userId 用户id
     * @return 是否失效
     */
    @Select("SELECT status FROM refresh_token WHERE user_id = #{userId}")
    Boolean selectRefreshTokenStatus(Integer userId);
}
